package com.kos.backend.service.impl.user.snake;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kos.backend.mapper.SnakeMapper;
import com.kos.backend.pojo.Snake;
import com.kos.backend.pojo.User;
import com.kos.backend.service.impl.utils.UserDetailsImpl;
import com.kos.backend.service.user.snake.QueryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

@Service
public class QueryServiceImpl implements QueryService {

    @Autowired
    private SnakeMapper snakeMapper;

    @Override
    public List<Snake> query() {
        UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
        UserDetailsImpl loginUser = (UserDetailsImpl) usernamePasswordAuthenticationToken.getPrincipal();
        User user = loginUser.getUser();
        int user_id = user.getId();
        QueryWrapper<Snake> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",user_id);
        return snakeMapper.selectList(queryWrapper);
    }
}
